package LeetCode.exercise;

public class LC844 {
    public static void main(String[] args) {
        LC844 test = new LC844();
        boolean b = test.backspaceCompare("ab#c", "ad#c");
        System.out.println(b);
    }
    public boolean backspaceCompare(String s, String t) {
        StringBuffer sb1 = new StringBuffer();
        StringBuffer sb2 = new StringBuffer();
        StringBuilder sb = new StringBuilder();
        char[] chars1 = s.toCharArray();
        char[] chars2 = t.toCharArray();
        for(char c1 : chars1){
            if(c1 == '#'){
                if(sb1.length() > 0){
                    sb1.deleteCharAt(sb1.length()-1);
                }
            } else {
                sb1.append(c1);
            }
        }
        for(char c2 : chars2){
            if(c2 == '#'){
                if(sb2.length() > 0){
                    sb2.deleteCharAt(sb2.length()-1);
                }
            } else {
                sb2.append(c2);
            }
        }
        return sb1.equals(sb2);
    }
}
